//
//  ThirdLoginView.m
//  PigMarket
//
//  Created by Felix on 2019/3/11.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "ThirdLoginView.h"

#define Spacing 15

@interface ThirdLoginView ()

/**
 leftLine
 */
@property (nonatomic , strong) UILabel *leftLine;

/**
 rightLine
 */
@property (nonatomic , strong) UILabel *rightLine;

/**
 title
 */
@property (nonatomic , strong) UILabel *title;

@end

@implementation ThirdLoginView

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.leftLine];
    [self addSubview:self.rightLine];
    [self addSubview:self.title];
    [self addSubview:self.qqLoginBtn];
    [self addSubview:self.wechatLoginBtn];
    [self addSubview:self.sinaLoginBtn];
}

- (void)initLayout {
    // 布局子控件
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.centerX.mas_equalTo(0);
    }];
    [self.leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(Spacing * 2);
        make.right.mas_equalTo(self.title.mas_left).offset(-Spacing);
        make.height.mas_equalTo(0.5);
        make.centerY.mas_equalTo(self.title.mas_centerY);
    }];
    [self.rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-Spacing * 2);
        make.left.mas_equalTo(self.title.mas_right).offset(Spacing);
        make.height.mas_equalTo(0.5);
        make.centerY.mas_equalTo(self.title.mas_centerY);
    }];
    [self.wechatLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.title.mas_bottom).offset(20);
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    [self.qqLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.wechatLoginBtn.mas_centerY);
        make.right.mas_equalTo(self.wechatLoginBtn.mas_left).offset(-Spacing * 2);
    }];
    [self.sinaLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.wechatLoginBtn.mas_centerY);
        make.left.mas_equalTo(self.wechatLoginBtn.mas_right).offset(Spacing * 2);
    }];
}

#pragma mark - getter and setter

- (UILabel *)leftLine {
    if (!_leftLine) {
        _leftLine = [[UILabel alloc] init];
        _leftLine.backgroundColor = [UIColor dividerColor];
    }
    return _leftLine;
}
- (UILabel *)rightLine {
    if (!_rightLine) {
        _rightLine = [[UILabel alloc] init];
        _rightLine.backgroundColor = [UIColor dividerColor];
    }
    return _rightLine;
}
- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = UIColorFromRGB(0x9C9FA1);
        _title.text = @"使用第三方账号登录";
        _title.font = mFont(13);
    }
    return _title;
}
- (HButtonView *)qqLoginBtn {
    if (!_qqLoginBtn) {
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_qq"]];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"QQ";
        titleLabel.font = [UIFont smallFont];
        titleLabel.textColor = [UIColor textMiddleGrayColor];
        
        _qqLoginBtn = [[HButtonView alloc] initWithTopIcon:iconView title:titleLabel];
    }
    return _qqLoginBtn;
}
- (HButtonView *)wechatLoginBtn {
    if (!_wechatLoginBtn) {
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_wechat"]];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"微信";
        titleLabel.font = [UIFont smallFont];
        titleLabel.textColor = [UIColor textMiddleGrayColor];
        
        _wechatLoginBtn = [[HButtonView alloc] initWithTopIcon:iconView title:titleLabel];
    }
    return _wechatLoginBtn;
}
- (HButtonView *)sinaLoginBtn {
    if (!_sinaLoginBtn) {
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_sina"]];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"微博";
        titleLabel.font = [UIFont smallFont];
        titleLabel.textColor = [UIColor textMiddleGrayColor];
        
        _sinaLoginBtn = [[HButtonView alloc] initWithTopIcon:iconView title:titleLabel];
    }
    return _sinaLoginBtn;
}

@end
